#include <iostream>
#include <nanomsg/nn.h>
#include <nanomsg/pipeline.h>
#include <nanomsg/pubsub.h>
#include <nanomsg/tcp.h>
#include "messages.pb.h"

int main() {
    int socket = nn_socket(AF_SP, NN_TCP_NODELAY);
    nn_connect(socket, "tcp://127.0.0.1:5555");

    Request request;
    request.set_data("World!");

    std::string serialized_request;
    request.SerializeToString(&serialized_request);

    nn_send(socket, serialized_request.c_str(), serialized_request.size(), 0);

    char* buffer = nullptr;
    int bytes = nn_recv(socket, &buffer, NN_MSG, 0);

    Response response;
    response.ParseFromArray(buffer, bytes);

    std::cout << "Received response: " << response.result() << std::endl;

    nn_freemsg(buffer);

    nn_shutdown(socket, 0);
    return 0;
}
